package com.onpositive.datamap.core.impl;

import java.io.Serializable;

import com.onpositive.datamap.core.IImageObject;
import com.onpositive.picture.utils.PictureGrabber;

public class LinkImageObject implements IImageObject,Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((link == null) ? 0 : link.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		LinkImageObject other = (LinkImageObject) obj;
		if (link == null) {
			if (other.link != null)
				return false;
		} else if (!link.equals(other.link))
			return false;
		return true;
	}

	final String link;
	final String caption;
	
	public LinkImageObject(String link, String caption) {
		super();
		this.link = link;
		this.caption = caption;
	}

	@Override
	public byte[] getBytes(int width, int height) {
		return new PictureGrabber().grabWikiPictur(link, width, height);
	}

	@Override
	public String getUrl(int width, int height) {
		String buildThumbPath = new PictureGrabber().buildThumbPath(link, width);
		if (buildThumbPath==null){
			return link;
		}
		return buildThumbPath;
	}

	@Override
	public String getCaption() {
		return caption;
	}

}
